/**
 * Created by Administrator on 2017/1/19 0019.
 */
var SCOPE = {
	image_host_url: 'http://sb.kaimobangwang.com/'
};
/**
 * 服务单状态
 */
function getOrderAustinServerStatus(status) {
	var statusText = ['', '下单成功', '待付款', '已付款', '服务中', '待确认', '订单完成', '申请售后', '申请仲裁', '订单取消', '待确认', '议价中'];
	return statusText[status];
}

function getLocalTime(nS) {
	var time = new Date(parseInt(nS) * 1000);
	if (arguments[1]) {
		return (time.getFullYear() < 10 ? '0' + time.getFullYear() : time.getFullYear()) + "-" +
		((parseInt(time.getMonth()) + 1) < 10 ? '0' + (parseInt(time.getMonth()) + 1) : (parseInt(time.getMonth()) + 1)) + "-" +
		(time.getDate() < 10 ? '0' + time.getDate() : time.getDate());
	} else {
		return (time.getFullYear() < 10 ? '0' + time.getFullYear() : time.getFullYear()) + "-" +
		((parseInt(time.getMonth()) + 1) < 10 ? '0' + (parseInt(time.getMonth()) + 1) : (parseInt(time.getMonth()) + 1)) + "-" +
		(time.getDate() < 10 ? '0' + time.getDate() : time.getDate()) + " " +
		(time.getHours() < 10 ? '0' + time.getHours() : time.getHours()) + ":" +
		(time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes()) + ":" +
		(time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds());
	}
}

function formattingTimestamp(time) {
	var d = new Date(time);
	if (arguments[1]) {
		return d.getFullYear() + "-" + d.getMonth() + 1 + "-" + d.getDate();
	} else {
		return d.getFullYear() + "-" + d.getMonth() + 1 + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
	}
}

/**
 * 绝对路径的uploads图片转为相对路径
 */
function get_uploads(str) {
	str = str.replace(/\\/g, "/");
	if (str.indexOf("uploads/") != -1) {
		return "uploads/" + str.split("uploads/")[1];
	} else {
		return str;
	}
}

/**
 * 是否微信浏览器
 * @returns {boolean}
 */
function isWeiXin() {
	var ua = window.navigator.userAgent.toLowerCase();
	if (ua.match(/MicroMessenger/i) == 'micromessenger') {
		return true;
	} else {
		return false;
	}
}

$(function () {
	/*
	 * 全局js
	 * */
	//ios终端
	window.isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
	//android终端
	window.isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1;
	// 上传文本框属性
	if (isiOS) {
		$('input[type="file"]').attr("multiple", "multiple");
	}
	if (isAndroid) {
		$('input[type="file"]').attr("capture", "camera");
	}

	/*
	 * 订单js
	 * */
	// 取消订单
	$(document).on('click', '.cancel_order', function () {
		var _this = $(this);
		$.confirm("确认取消?", '', function () {
                        $('#loadingToast').hide();
			//确认
			var id = _this.data('order-id');
			var model = _this.data('model');
			$.get(root + "user/orders/cancel_order", {
				id: id,
				model: model
			}, function (msg) {
				if (msg.code == 200) {
					if (_this.hasClass("order_list")) {
						_this.text('已取消');
						_this.parents('.js-list').find(".action p").text('已取消');
					} else {
						_this.text('已取消').prev().remove();
						$(".action").text('已取消');
					}
					_this.removeClass('cancel_order');
				} else {
					$.alert(error_code[msg.code]);
				}
			}, 'json');
		}, function () {
                        $('#loadingToast').hide();
			//取消
			return false;
		});
		//confirm结束
	});

	// 重新推送订单
	$(document).on('click', '.order_push_again', function () {
		//点击确认
		var _this = $(this);
		var id = _this.data('order-id');
		var model = _this.data('model');
		//如果参数过多，建议通过 object 方式传入
		$.prompt({
			//            title: '订单取消后将返回需求池重新推送',
			title: '订单取消需求重新推送',
			text: '请输入取消原因',
			input: '',
			empty: false, // 是否允许为空
			onOK: function (input) {
                                $('#loadingToast').fadeIn(100);
				$.get(root + "user/orders/push_again", {
					id: id,
					model: model,
					msg: input
				}, function (msg) {
					$('#loadingToast').hide();
					if (msg.code == 200) {
						$.alert('推送成功！！', '');
						window.location.reload();
					} else {
						$.alert(error_code[msg.code]);
					}
				}, 'json');
			},
			onCancel: function () {
				//点击取消
				$('#loadingToast').hide();
				return false;
			}
		});
	});

	// 确认完成
	$(document).on('click', '.affirm_finish', function () {
		//点击确认
		var _this = $(this);
		$.confirm('确认完成订单！！', function () {
			//确认
			$('#loadingToast').fadeIn(100);
			var id = _this.data('order-id');
			var model = _this.data('model');
			$.get(root + "user/orders/affirm_finish", {
				id: id,
				model: model
			}, function (msg) {
				$('#loadingToast').hide();
				if (msg.code == 200) {
					$.alert('操作成功！', '');
					if (_this.hasClass("order_list")) {
						_this.parents('.status').find("span").text('订单完成');
					} else {
						$(".action").text('订单完成');
					}

					var _type = model == 'order_server' ? 2 : 1;
					_this.text('待评价').attr('href', root + 'user/comment/index/order_id/' + id + '/type/' + _type).removeClass('affirm_finish').next().text('申请售后');
				} else {
					$.alert(error_code[msg.code]);
				}
			}, 'json');
		}, function () {
                        $('#loadingToast').hide();
			//取消
			return false;
		});
	});
});

//改写原生alert lizhien 20170502
window.alert = function (s) {
	$.alert(s);
};

// 切换显示内容
var li_px1_click = function () {
	$('.slide').addClass('slide2').removeClass('slide1');
	$('.li-px1-sp1').addClass('cl-blue');
	$('.li-px1-sp2').removeClass('cl-blue');
	$('.g-jyzk-div-dis').css('display', 'block');
	$('.displaynone').css('display', 'none');
};

var li_px2_click = function () {
	$('.li-px1-sp1').removeClass('cl-blue');
	$('.li-px1-sp2').addClass('cl-blue');
	$('.g-jyzk-div-dis').css('display', 'none');
	$('.displaynone').css('display', 'block');
};

// 切换显示内容=====end
